#include "../../include/Tileset/tilesetObjectGroup.hpp"
#include "../../include/Tileset/tilesetObject.hpp"
#include <tinyxml.h>

namespace Tmx {
  ObjectGroup::ObjectGroup(int _depth) {
	x = 0;
	y = 0;
	width = 0;
	height = 0;
	opacity = 1;
	visible = 1;
	depth = _depth;
  }
  ObjectGroup::~ObjectGroup() {
	  std::vector<Object *>::iterator iter;
	  for (iter = objects.begin(); iter != objects.end(); iter++) {
		  Object *obj = *iter;
		  delete obj;
	  }
  }
  
  void ObjectGroup::parse(TiXmlNode *objectGroupNode)
  {
	double opac;
    TiXmlElement *objectGroupElement = objectGroupNode->ToElement();
	name = objectGroupElement->Attribute("name");
	//color= objectGroupElement->Attribute("color");
	objectGroupElement->Attribute("width", &width);
	objectGroupElement->Attribute("height", &height);
	objectGroupElement->Attribute("opacity", &opac);
	opacity = (float) opac;
	objectGroupElement->Attribute("visible", &visible);
	TiXmlNode *objectNode = objectGroupNode->FirstChild("object");
	// iterate through objects
	while (objectNode) {
	  Object *object = new Object();
	  object->parse(objectNode);
	  objects.push_back(object);
	  objectNode = objectGroupNode->IterateChildren("object", objectNode);
	}
  }
}; // namespace Tmx
